package com.lzj.demo.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzj.demo.dto.Account;
import com.lzj.demo.mapper.AccountMapper;
import com.lzj.demo.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * (Account)表服务实现类
 *
 * @author makejava
 * @since 2023-02-09 09:42:36
 */
@Slf4j
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    public boolean decrease(Long userId, BigDecimal money) {
        Account account = lambdaQuery().eq(Account::getUserId,userId).one();
        return lambdaUpdate().set(Account::getResidue,account.getResidue().subtract(money))
                .set(Account::getUsed,account.getUsed().add(money))
                .eq(Account::getUserId,userId).update();
    }
}

